package itheima.com.SocketTCP;

import java.io.*;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;

public class SocketServe {

    public static void main(String[] args) throws IOException {

        ServerSocket serverSocket = new ServerSocket(9999);
        Socket accept = serverSocket.accept();

//        byte[] buf = new byte[1024];
//        int readlen = 0;
        InputStream inputStream = accept.getInputStream();
//        while ((readlen = inputStream.read(buf)) != -1) {
//            System.out.println("读取数据=》》》"+new String(buf, 0, readlen));
//        }
//       字符流IO流
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
        String s = bufferedReader.readLine();
        System.out.println(s);

//        获取socket相关的输出流
        OutputStream outputStream = accept.getOutputStream();
        BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(outputStream));
        bufferedWriter.write("hello word 字符流。。。。");
        bufferedWriter.newLine();
        bufferedWriter.flush();

        accept.shutdownOutput();
        bufferedWriter.close();
        serverSocket.close();
        accept.close();
        inputStream.close();


    }

}
